//
//  PublishedLoginView.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/1.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "PublishedLoginView.h"
#import "HistoryNumView.h"
#import "RolesVC.h"
#import "WYPublicWeb.h"
#import "OtherDuoBaoVC.h"
//计算详细
#define JSXX_URL @"api/ApiGoods/getGameRulesDetail?id="
@interface PublishedLoginView ()
{
    __weak IBOutlet UILabel *jxzLab;
    __weak IBOutlet UILabel *titleLab;
    
    __weak IBOutlet UIImageView *imglab;
    __weak IBOutlet UILabel *countLab;
    __weak IBOutlet UILabel *addressLab;
    __weak IBOutlet UILabel *num1Lab;
    __weak IBOutlet UILabel *timeLab;
    __weak IBOutlet UILabel *xyNumLab;
    __weak IBOutlet UIView *bgView;
    __weak IBOutlet UIView *bgView1;
    __weak IBOutlet UIButton *cyBtn;
    __weak IBOutlet UIButton *jsBtn;
    __weak IBOutlet UIView *bgView2;
    __weak IBOutlet UILabel *numLab;
    
    __weak IBOutlet UIView *redBg;
    __weak IBOutlet UIButton *mcyBtn;
    
    __weak IBOutlet UILabel *tsLab;
    
}
@end
@implementation PublishedLoginView

- (void)awakeFromNib
{
    if(WYMWITH > 320){
        tsLab.font = [UIFont systemFontOfSize:14];
    }
    jxzLab.textColor = QBB_RED_COLOR;
    jxzLab.layer.borderWidth = 1;
    jxzLab.layer.borderColor = QBB_RED_COLOR.CGColor;
    jxzLab.layer.masksToBounds = YES;
    jxzLab.layer.cornerRadius = 2;
    bgView1.layer.masksToBounds = YES;
    bgView1.layer.cornerRadius = 2;
    bgView1.backgroundColor = QBB_RED_COLOR;
    cyBtn.layer.borderWidth = 1;
    cyBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    cyBtn.layer.masksToBounds = YES;
    cyBtn.layer.cornerRadius = 2;
    cyBtn.backgroundColor = QBB_RED_COLOR;
    jsBtn.layer.borderWidth = 1;
    jsBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    jsBtn.layer.masksToBounds = YES;
    jsBtn.layer.cornerRadius = 2;
    jsBtn.backgroundColor = QBB_RED_COLOR;
    imglab.layer.masksToBounds = YES;
    imglab.layer.cornerRadius = imglab.frame.size.width/2;
    bgView2.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Dbb_backColor"]];
    bgView2.layer.masksToBounds = YES;
    bgView2.layer.cornerRadius = 2;
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = 2;
    bgView.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0];
    bgView.layer.borderWidth = 0.5;
    bgView.layer.borderColor = [UIColor lightGrayColor].CGColor;

    mcyBtn.backgroundColor = QBB_RED_COLOR;
    cyBtn.backgroundColor = QBB_RED_COLOR;
    jsBtn.backgroundColor = QBB_RED_COLOR;
    mcyBtn.layer.cornerRadius =2;
    mcyBtn.layer.masksToBounds = YES;
    redBg.backgroundColor = QBB_RED_COLOR;
    if(WYMWITH>320){
        imglab.frame = CGRectMake((imglab.frame.origin.x+10)*AUTOX, imglab.frame.origin.y*AUTOY, imglab.frame.size.width, imglab.frame.size.height);
    }
    imglab.layer.borderWidth = 2;
    imglab.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //给头像添加点击事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgOnClick)];
    imglab.userInteractionEnabled = YES;
    [imglab addGestureRecognizer:tap];
}
- (void)imgOnClick
{
    OtherDuoBaoVC *otherVC = [[OtherDuoBaoVC alloc]init];
    if ([self.owner_uid class] != [NSNull class]) {
        otherVC.uid = self.owner_uid;
        [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:otherVC animated:YES];
    }
}

//填充view数据的方法
- (void)fillViewWithDic:(NSDictionary *)dic
{
    if ([dic[@"goods"][@"title"] class] != [NSNull class]) {
        titleLab.text = [NSString stringWithFormat:@"(第%@期)%@",dic[@"goods"][@"qishu"],dic[@"goods"][@"title"]];
        self.pdc_id = dic[@"goods"][@"id"];
        self.pdc_qishu = dic[@"goods"][@"qishu"];
        self.owner_uid = dic[@"goods"][@"uid"];
    }else{
        titleLab.text = @"***";
    }
    if ([dic[@"goods"][@"username"] class] != [NSNull class]) {
        countLab.text = dic[@"goods"][@"username"];
    }else{
        countLab.text = @"***";
    }
    
    if ([dic[@"goods"][@"addr"] class] != [NSNull class]) {
        addressLab.text = dic[@"goods"][@"addr"];
    }else{
        addressLab.text = @"地址待定";
    }
    if ([dic[@"goods"][@"q_user_code"] class] != [NSNull class]) {
        xyNumLab.text = dic[@"goods"][@"q_user_code"];
    }else{
        xyNumLab.text = @"***";
    }
    if ([dic[@"goods"][@"your_go_total"] class] != [NSNull class]) {
        NSNumber *mun = dic[@"goods"][@"your_go_total"];
        numLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"" Middle:[NSString stringWithFormat:@"%d",[mun intValue]] RightStr:@"次" Font:12];
    }else{
        numLab.text = @"***";
    }
    
    if ([dic[@"goods"][@"go_total"] class] != [NSNull class]) {
        NSNumber *mun = dic[@"goods"][@"go_total"];
        num1Lab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"" Middle:[NSString stringWithFormat:@"%d",[mun intValue]] RightStr:@"次" Font:14];
    }else{
        num1Lab.text = @"***";
    }
    timeLab.text = dic[@"goods"][@"q_end_time"];
    [imglab sd_setImageWithURL:[NSURL URLWithString:dic[@"goods"][@"img_url"]] placeholderImage:[UIImage imageNamed:@"iphone_5"]];
}

//参与号码按钮
- (IBAction)canyuBtnOnClick:(id)sender {
    HistoryNumView *his = [[HistoryNumView alloc]initWithPdcId:self.pdc_id AndQiShu:self.pdc_qishu AndTitle:titleLab.text Owner:self.owner_uid];
//    NSLog(@"-----》pdc=%@,s=%@,o=%@",self.pdc_id,[UserInfo getUserID],self.owner_uid);
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    [window addSubview:his];
}

//自己的参与号码
- (IBAction)selfCanyuBtn:(id)sender {
    HistoryNumView *his = [[HistoryNumView alloc]initWithPdcId:self.pdc_id AndQiShu:self.pdc_qishu AndTitle:titleLab.text Owner:[UserInfo getUserID]];
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    [window addSubview:his];

}

//计算详细 进入开奖规则界面
- (IBAction)jsxxBtnOnClick:(id)sender {
    WYPublicWeb *web = [[WYPublicWeb alloc]init];
    web.mtitle = @"计算详情";
    NSString *newIp = [DBB_IP stringByReplacingOccurrencesOfString:@"?/" withString:@""];
    web.urlStr = [NSString stringWithFormat:@"%@%@%@",newIp,JSXX_URL,self.pdc_id];
    [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:web animated:YES];
}
@end
